package com.hanxiaozhang.base.controller;

import com.alibaba.fastjson.JSON;
import com.hanxiaozhang.config.GeneratorProperties;
import com.hanxiaozhang.result.Result;
import com.hanxiaozhang.security.CurrentUser;
import com.hanxiaozhang.security.CurrentUserUtil;
import com.hanxiaozhang.util.JsonUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.security.Principal;
import java.util.LinkedHashMap;

/**
 * 〈一句话功能简述〉<br>
 * 〈测试〉
 *
 * @author hanxinghua
 * @create 2021/3/23
 * @since 1.0.0
 */
@Slf4j
@Controller
public class TestController {

    @Autowired
    private GeneratorProperties generatorProperties;

    @ResponseBody
    @GetMapping("/test")
    public Result test(@RequestHeader("Authorization") String token) {
        log.info("token:[{}]",token);
        return Result.success();
    }

    @ResponseBody
    @GetMapping("/test1")
    public Result test1() {
        System.out.println(CurrentUserUtil.getUserId());
        System.out.println(CurrentUserUtil.getName());
        System.out.println(CurrentUserUtil.getUserName());
        return Result.success();
    }

    @GetMapping("/tokenUser")
    @ResponseBody
    public Principal user(Principal user){
        return user;
    }


    @GetMapping("/test2")
    @ResponseBody
    public String test2(){
        generatorProperties.toString();
        return generatorProperties.toString();
    }



}
